/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.cezary.butler.walili.server.db;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import pl.cezary.butler.walili.server.config.ServerConfiguration;

/**
 *
 * @author Cezary Butler
 */
public class DatabaseSqlite extends Database {

    private static final String DRIVER = "org.sqlite.JDBC";
    private String FILE = ServerConfiguration.getInstance().getDbFile();
    private static final Logger log = Logger.getLogger("BazaDanychSqlite");

    public DatabaseSqlite() {
        polacz();
    }
    
    public DatabaseSqlite(String s) {
        FILE = s;
        polacz();
    }
    
    private static DatabaseSqlite instancja = null;

    public static DatabaseSqlite getInstance() {
        return (instancja == null) ? instancja = new DatabaseSqlite() : instancja;
    }


    @Override
    protected Class<? extends Driver> getDriverClass() throws RuntimeException {
        try {
            Driver d = (Driver) Class.forName(DRIVER).newInstance();
            return d.getClass();
        } catch (Exception ex) {
            log.log(Level.SEVERE,"Problem z pobraniem sterownika sqlite",ex);
            throw new RuntimeException(ex);
        }
    }

    protected Connection createConnection() throws RuntimeException {
        try {
            log.fine("Tworzenie połączenia sqlite");
            return DriverManager.getConnection(getConnectionUrl());
        } catch (SQLException ex) {
            log.log(Level.SEVERE,"Problem podczas tworzenia polaczenia z bd",ex);
            throw new RuntimeException(ex);
        }
    }


    @Override
    protected String getDbInitPath() {
        return "builder_sqlite.sql";
    }

    @Override
    protected String getConnectionUrl() {
        return "jdbc:sqlite:" + FILE;
    }

    @Override
    protected String getUsername() {
        return  "";
    }

    @Override
    protected String getPassword() {
        return "";
    }
    
    
    
    
}
